import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:dio/dio.dart';
import 'package:provide/provide.dart';
import '../provide/person.dart';
import '../provide/details_info.dart';
import 'package:fluttertoast/fluttertoast.dart';

class BottomInput extends StatefulWidget {
  final Widget child;

  BottomInput({Key key, this.child}) : super(key: key);

  _BottomInputState createState() => _BottomInputState();
}

class _BottomInputState extends State<BottomInput> {
  TextEditingController _commentController = new TextEditingController();
  @override
  Widget build(BuildContext context) {
    return Provide<PersonnalProvider>(
      builder: (context,child,val){
        return Container(
          height: ScreenUtil().setHeight(80),
          width: ScreenUtil().setWidth(750),
          padding: EdgeInsets.fromLTRB(10, 0, 0, 0),
          decoration: BoxDecoration(
            // color: Colors.grey
          ),
          child: Row(
            children: <Widget>[
              Container(
                padding: EdgeInsets.fromLTRB(ScreenUtil().setWidth(15), ScreenUtil().setHeight(35), 0, 0),
                decoration: BoxDecoration(
                  color: Colors.grey,
                  borderRadius: BorderRadius.circular(10),
                  border: Border.all(width: 1,color: Colors.black12)
                ),
                width: ScreenUtil().setWidth(600),
                height: ScreenUtil().setHeight(80),
                child: TextField(
                  controller: _commentController,
                  decoration: InputDecoration(
                      hintText: "请输入您的评论",
                      border: InputBorder.none, //隐藏下划线
                      fillColor: Colors.pink
                  )
                ),
              ),
              InkWell(
                onTap: (){
                  // 点击发送评论
                  if(_commentController.text==''){
                    Fluttertoast.showToast(
                      msg: "评论为空",
                      toastLength: Toast.LENGTH_SHORT,
                      gravity: ToastGravity.BOTTOM,
                      timeInSecForIos: 1,
                      backgroundColor: Colors.pink,
                      textColor: Colors.white,
                      fontSize: 16.0
                    );
                    return;
                  }
                  Provide.value<DetailsInfoProvide>(context).postComment(_commentController.text, val.token,context);
                  _commentController.clear();
                },
                child: Container(
                  alignment: Alignment(0, 0),
                  width: ScreenUtil().setWidth(90),
                  height: ScreenUtil().setHeight(70),
                  margin: EdgeInsets.only(left: 10),
                  decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(10),
                    color: Colors.pink
                  ),
                  child: Text(
                    '发送',
                    style: TextStyle(fontSize: 18),
                  ),
                ),
              )
            ],
          ),
        );
      },
    );
  }
}